//
//  KATWaitingAnimationView.m
//  KATFramework
//
//  Created by Yi Yu on 2017/5/24.
//  Copyright © 2017年 KatApp. All rights reserved.
//

#import "KATWaitingAnimationView.h"

@implementation KATWaitingAnimationView

#pragma -mark 类方法

///获取实例
+ (instancetype)animationWithFrame:(CGRect)frame
{
    KATWaitingAnimationView *anim=[[[self alloc] init] autorelease];
    
    anim.frame=frame;
    anim.backgroundColor=[UIColor clearColor];
    anim.ringCut=1.0/12.0;
    anim.cycleDuration=1.0;
    
    //环
    anim.ringShape=[KATShapeUtil arcShapeWithRadius:frame.size.height*0.5 startAngle:M_PI*3.5 endAngle:M_PI*1.5 clockwise:NO];
    anim.ringShape.fillColor=[UIColor clearColor].CGColor;
    anim.ringShape.frame=anim.bounds;
    [anim.layer addSublayer:anim.ringShape];
    
    [anim restore];
        
    return anim;
}


#pragma -mark 对象方法

//复位
- (void)restore
{
    [_ringShape clearAnimations];
    [_ringShape restoreShape];
    _ringShape.strokeStart=0;
    _ringShape.strokeEnd=0;
}



//播放
- (void)play
{
    if(!_ringShape.animating)
    {
         [self restore];
        
        [_ringShape startAnimation:[_ringShape animationStrokeEndToValue:1.0-_ringCut withDuration:(1.0-_ringCut)*_cycleDuration repeat:1 autoreverses:NO delay:0] andDelay:0];
        [_ringShape rotateWithDuration:_cycleDuration repeat:-1 clockwise:NO];
    }
}


//重新播放
- (void)replay
{
    [self stop];
    
    [self play];
}


//停止
- (void)stop
{
    [_ringShape stopAnimation];
}



//释放内存
- (void)dealloc
{
    [_ringShape release];
    
    [super dealloc];
}


@end
